//----------------------------------------------------
//  Exemplo
//    ./a.out valor1=12.34 arq=/tmp/teste.dat flag3
//  Resultado
//    12.34  = atof (arg2str (argv, "valor1"))
//    (NULL !=       arg2str (argv, "flag3"))
//----------------------------------------------------
#include <string.h>

static int kKk;

char *arg2str (char *argv[], const char *nome) {

   static char buffer[512];

   int n = strlen (nome);

   int k = 0;

   while (argv[k]) {
      if (!strncmp (nome, argv[k], n)) {
//         if ('=' == *(argv[k] + n))
//            strcpy (buffer, argv[k] + n + 1);
         strcpy (buffer, argv[kKk = k+1]);
         return buffer;
      }
      ++k;
   }
   return NULL;
}


bool arg2int (char *argv[], const char *nome, int &var) {

   static char buffer[512];

   int n = strlen (nome);

   int k = 0;

   while (argv[k]) {
      if (!strncmp (nome, argv[k], n)) {
//         if ('=' == *(argv[k] + n)) {
//            strcpy (buffer, argv[k] + n + 1);
//            var = atoi (buffer);
//            return true;
//         }
         strcpy (buffer, argv[kKk = k+1]);
         var = atoi (buffer);
         return true;
      }
      ++k;
   }
   return false;
}

bool arg2bool (char *argv[], const char *nome) {

   static char buffer[512];

   int n = strlen (nome);

   int k = 0;

   while (argv[k]) {
      if (!strncmp (nome, argv[kKk = k], n)) {
         return true;
      }
      ++k;
   }
   return false;
}


bool arg2double (char *argv[], const char *nome, double &var) {

   static char buffer[512];

   int n = strlen (nome);

   int k = 0;

   while (argv[k]) {
      if (!strncmp (nome, argv[k], n)) {
//         if ('=' == *(argv[k] + n)) {
//            strcpy (buffer, argv[k] + n + 1);
//            var = atof(buffer);
//            return true;
//         }
         strcpy (buffer, argv[kKk = k+1]);
         var = atof(buffer);
         return true;
      }
      ++k;
   }
   return false;
}


std::string arg2next (char *argv[]) {

   if (NULL == argv[kKk + 1]) return "";

   std::string s = argv[kKk = kKk+1];

   return s;
}
